/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.pig4cloud.pigx.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.common.core.constant.enums.OrderStatusEnum;
import com.pig4cloud.pigx.order.api.entity.OrderDelivery;
import com.pig4cloud.pigx.order.api.entity.OrderInfo;
import com.pig4cloud.pigx.order.api.entity.PointSpuOrder;
import com.pig4cloud.pigx.order.mapper.OrderDeliveryMapper;
import com.pig4cloud.pigx.order.mapper.OrderInfoMapper;
import com.pig4cloud.pigx.order.mapper.PointSpuOrderMapper;
import com.pig4cloud.pigx.order.service.OrderDeliveryService;
import com.pig4cloud.pigx.order.service.OrderInfoService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 订单物流
 *
 * @author pigx code generator
 * @date 2023-12-16 19:16:58
 */
@Service
@AllArgsConstructor
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OrderDelivery>
		implements OrderDeliveryService {

	private final OrderInfoMapper orderInfoMapper;

	private final PointSpuOrderMapper pointSpuOrderMapper;

	/**
	 * 添加订单物流
	 * @param orderDelivery
	 * @return
	 */
	@Override
	public boolean addOrderDelivery(OrderDelivery orderDelivery) {

		// 添加物流信息
		this.save(orderDelivery);

		if (orderDelivery.getDeliveryOrderType().equals("1")) {
			// 商品订单的场合
			OrderInfo orderInfo = new OrderInfo();
			orderInfo.setId(orderDelivery.getOrderId());
			orderInfo.setSendTime(LocalDateTime.now());
			orderInfo.setOrderStatus(OrderStatusEnum.SHIPPED.getType());
			orderInfoMapper.updateById(orderInfo);
		}
		else if (orderDelivery.getDeliveryOrderType().equals("2")) {
			// 礼品订单的场合
		}
		else {
			// 积分订单
			PointSpuOrder pointSpuOrder = new PointSpuOrder();
			pointSpuOrder.setId(orderDelivery.getOrderId());
			pointSpuOrder.setSendTime(LocalDateTime.now());
			pointSpuOrder.setOrderStatus(OrderStatusEnum.SHIPPED.getType());
			pointSpuOrderMapper.updateById(pointSpuOrder);
		}

		return true;
	}

}
